using System;
using System.Collections.Generic;
using I2.Loc;
using Rilisoft.MiniJson;
using UnityEngine;

public class GameModeConfig : ScriptableObject
{
	[Serializable]
	public class ModeInfo
	{
		public string name;

		public string playerCount;

		public GameModesUI.TransportType typeTransport;

		public TypeGame typeGame;

		public int order;

		public bool isNew;

		private Dictionary<string, string> _translateName;

		private GameObject _animation;

		private GameObject _texture;

		private GameObject _animationPreview;

		private Dictionary<int, string[]> _modeNameList;

		public Dictionary<string, string> GetTranslateName()
		{
			if (_translateName == null)
			{
				Dictionary<int, string[]> modesNames = GetModesNames();
				int idModeByTypeGame = BCWServer.GetIdModeByTypeGame(typeGame);
				_translateName = new Dictionary<string, string>();
				foreach (string allLanguage in LocalizationManager.GetAllLanguages())
				{
					int languageIndex = LocalizationManager.GetLanguageIndex(allLanguage);
					if (modesNames.ContainsKey(idModeByTypeGame) && languageIndex < modesNames[idModeByTypeGame].Length)
					{
						_translateName.Add(allLanguage, modesNames[idModeByTypeGame][languageIndex]);
						continue;
					}
					string currentLanguage = LocalizationManager.CurrentLanguage;
					LocalizationManager.CurrentLanguage = allLanguage;
					_translateName.Add(allLanguage, (!string.IsNullOrEmpty(ScriptLocalization.Get("Game_Common/sm_" + name + "_title"))) ? ScriptLocalization.Get("Game_Common/sm_" + name + "_title") : name);
					LocalizationManager.CurrentLanguage = currentLanguage;
				}
			}
			return _translateName;
		}

		public GameObject GetAnimation()
		{
			if (null == _animation)
			{
				_animation = (GameObject)Resources.Load("Prefabs/UI_SelectMode/SelectMode/" + name + "_SelectMode", typeof(GameObject));
			}
			return _animation;
		}

		public GameObject GetTexture()
		{
			if (null == _texture)
			{
				_texture = (GameObject)Resources.Load("Prefabs/UI_SelectMode/UnSelectMode/" + name + "_UnSelectMode", typeof(GameObject));
			}
			return _texture;
		}

		public GameObject GetAnimationPreview()
		{
			if (null == _animationPreview)
			{
				_animationPreview = (GameObject)Resources.Load("Prefabs/UI_SelectMode/SettingsMode/" + name + "_SettingsMode", typeof(GameObject));
			}
			return _animationPreview;
		}

		private Dictionary<int, string[]> GetModesNames()
		{
			if (_modeNameList == null)
			{
				_modeNameList = ParseSettingsJson(JSONManager.Instance.GetJSON(URLs.ModeNameSettings));
			}
			return _modeNameList;
		}

		private Dictionary<int, string[]> ParseSettingsJson(string result)
		{
			Dictionary<int, string[]> dictionary = new Dictionary<int, string[]>();
			Dictionary<string, object> dictionary2 = Json.Deserialize(result) as Dictionary<string, object>;
			if (dictionary2 != null)
			{
				foreach (KeyValuePair<string, object> item in dictionary2)
				{
					List<string> list = new List<string>();
					List<object> list2 = item.Value as List<object>;
					foreach (object item2 in list2)
					{
						list.Add(item2.ToString());
					}
					dictionary.Add(Convert.ToInt32(item.Key), list.ToArray());
				}
			}
			return dictionary;
		}
	}

	[SerializeField]
	private List<ModeInfo> modes;

	public List<ModeInfo> ModesConfig
	{
		get
		{
			return modes;
		}
	}

	public static bool CurrentModeIsTitans
	{
		get
		{
			if (GameController.instance == null)
			{
				return false;
			}
			return GameController.instance.curTypeGame == TypeGame.WalkingRobots || GameController.instance.curTypeGame == TypeGame.TitanfallV2;
		}
	}
}
